module sample_data

    integer sample_nx(3)
    integer :: num_sample
    real :: sample_dx(3)
    real, allocatable :: sample_x(:,:)
    real, allocatable :: sample_f(:)
    real :: volume

contains

    subroutine sample_data_init(num_dim, boundary)
        integer, intent(in) :: num_dim
        real, intent(in) :: boundary(2,num_dim)

        integer :: i, j, k, o(3)
        real :: temp1, temp2

        sample_nx = 1
        num_sample = 1
        do i = 1, num_dim
            sample_nx(i) = 200
            num_sample = num_sample*sample_nx(i)
        end do

        volume = 1.0
        do i = 1, num_dim
            sample_dx(i) = (boundary(2,i)-boundary(1,i))/(sample_nx(i)-1)
            volume = volume*sample_dx(i)
        end do

        allocate(sample_x(num_dim,num_sample))
        allocate(sample_f(num_sample))

        do j = 1, num_sample
            temp1 = j
            do i = num_dim, 2, -1
                temp2 = 1
                do k = 1, i-1
                    temp2 = temp2*sample_nx(k)
                end do
                o(i) = int((temp1-1)/temp2)+1
                temp1 = mod(temp1, temp2)
            end do
            if(temp1 == 0) then
                o(1) = sample_nx(1)
            else
                o(1) = temp1
            end if
            do i = 1, num_dim
                sample_x(i,j) = boundary(1,i)+(o(i)-1)*sample_dx(i)
            end do
        end do

        return
    end subroutine sample_data_init

end module sample_data
